#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QToolBar>
#include <QtSql>

#include "logger.h"
#include "my_defs.h"

#include "dbworker.h"
#include "styleloader.h"
#include "stylesdialog.h"

#include "batchinsertthread.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void setupWindow();
    void setupMenu();
    void linkModelsToViews();
    void closeEvent(QCloseEvent *e);
    void setStyleIdDelegates();

public slots:
    void refreshViews();
    void showAddRecordForm();
    void showChangeRecordForm();

private slots:
    void searchRecord();
    void on_btnGo_clicked();
    void on_commandLinkButton_clicked();
    void on_bntSaveQuery_clicked();
    void showContextMenuForTblViewQuery(const QPoint &);
    void showContextMenuForTree(const QPoint &p);
    void editRecord(QModelIndex m) { Q_UNUSED(m); qDebug()<<"YE!"; }

    // for menu:
    void createNewDb();
    void saveDbAs();
    void importDb();
    void exportDb();
    void loadDb();
    void exitApp();

    // for help
    void showHelp();
    void showAbout();
    void showQtHelp();

    // for importing DB:
    void importThreadStarted();
    void importThreadFinished();

private:
    bool userReallyWantsToQuit();
    void writeSettings();

    void setupContextMenu();

    void export2txt(const QString fileName);
    void exort2html(const QString fileName);

    QMenu *recordMenu;
    QAction *edtAct, *delAct, *newAct;

    QMenu *dbMenu, *settingsMenu, *helpMenu;
    // DB actions
    QAction *saveDbAct, *exportDbAct,
    *importDbAct, *newDbAct, *loadDbAct,
    // settings actions
    *settingsAct,
    // help actioins
    *helpAct, *aboutQtAct, *aboutAct, *exitAct;

    Ui::MainWindow *ui;


    int selectedUniqId;

protected:
    virtual void changeEvent(QEvent *e);

signals:
    void searchNeeded();
};

#endif // MAINWINDOW_H
